package com.ivo.web.form.def;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.ivo.util.StringUtil;
import com.ivo.web.form.intf.Field;

public class TextField extends FieldImpl implements Field
{
	protected String label;
	protected int maxLength;
	protected String tooltip;

	public String getLabel()
	{
		return label;
	}

	public void setLabel(String label)
	{
		this.label = label;
	}

	public int getMaxLength()
	{
		return maxLength;
	}

	public void setMaxLength(int maxLength)
	{
		this.maxLength = maxLength;
	}

	public String getTooltip()
	{
		return tooltip;
	}

	public void setTooltip(String tooltip)
	{
		this.tooltip = tooltip;
	}

	@Override
	public String toHtml()
	{
		Document document = DocumentHelper.createDocument();
		Element div = document.addElement( "input" );
		div.addAttribute( "type", "text" );
		if( StringUtil.notEmpty( id ) ) div.addAttribute( "id", id );
		if( StringUtil.notEmpty( name ) ) div.addAttribute( "name", name );
		if( StringUtil.notEmpty( style ) ) div.addAttribute( "style", style );
		if( StringUtil.notEmpty( css ) ) div.addAttribute( "css", css );
		if( StringUtil.notEmpty( width ) ) div.addAttribute( "width", width );
		if( StringUtil.notEmpty( height ) ) div.addAttribute( "height", height );
		if( StringUtil.notEmpty( value ) ) div.addAttribute( "value", value );
		//-------------------------------------------------------------------
		return div.asXML();
	}
}
